$(function () {
    var grid = $('#ywkejph_grid').edatagrid({
        url: $.webPath() + '/jhgl/bgjhywk/ejphkc',
        toolbar: "#ywkejph_toolbar",
        rownumbers: true,
        singleSelect: true,
        collapsible: true,
        pageNumber: 1,
        fit: true,
        fitColumns: true,
        queryParams: {
            mxid: $("#bgjhywk_bgjhhzmx_id").val()
        },
        columns: [
            [
                {field: 'ck.id', title: '仓库ID', hidden: true},
                {field: 'ck.mc', title: '仓库',align: 'center', width: 50},
                {field: 'kh.id', title: '卡号ID', hidden: true},
                {field: 'kh.khbm', title: '卡号', width: 50,align: 'center'},
                {field: 'kh.sl', title: '可平衡数量',align: 'right', formatter:function(value){
                    var sl = formatSl(value,",");
                    return sl;
                },width: 50},
                {field: 'phsl', title: '平衡数量', width: 50, align: 'right',
                    formatter:function(value){
                        var sl = formatSl(value,",");
                        return sl;
                    },editor: {type: 'numberbox', options: {min: 0, groupSeparator: ',', precision: 4}}},
                {field: 'kh.wsdj', title: '无税单价', width: 50, align: 'right',
                    formatter:function(value){
                        var sl = formatJe(value,",");
                        return sl;
                    }
                },
                {field: 'kh.wsje', title: '无税金额', width: 50,  align: 'right',
                    formatter:function(value){
                        var sl = formatJe(value,",");
                        return sl;
                    }
                }
            ]
        ],
        onClickRow: function (rowIndex, rowData) {
            datagridOnSelectHandle(rowIndex, rowData);
        },
        onLoadSuccess:function(){
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    });

    function datagridOnSelectHandle(rowIndex, rowData) {
        //获取每个单元格
        $(grid).edatagrid('editRow', rowIndex);
        var editors = $(grid).datagrid('getEditors', rowIndex);
        if (editors.length == 0)
            return;
        var phslEditor = editors[0];
        $(phslEditor.target).numberbox({min: 0, max: rowData['kh.sl']});
    }
});